<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link type="text/css" rel="stylesheet" href="__STATIC__/english/css/style.css" />
<title>英语</title>
<script language="javascript" src="__STATIC__/jquery-2.0.3.min.js"></script> 
<!-- <script language="javascript" src="__STATIC__/english/js/reg.js"></script> -->
</head>

<body>
<header>
  <img src="__STATIC__/english/images/header.jpg">
  <div class="w">
    <p>适合3-12岁孩子的美式英语课堂</p>
    <p>4节英文课：3节中教课+1节外教课</p>
    <p>学习自然拼读，英语对话英文歌曲，迅速提升孩子英语学习兴趣，纠正口语发音</p>
  </div>
</header>
<section class="content">
    <div class="notice_msg" style="display: block;
    width: 100%;
    box-sizing: border-box;
    background: #FF0047;
    border: 0;
    line-height: 46px;
    color: #fff;
    font-size: 18px;
    font-weight: bold;margin-bottom: 2px;padding-left: 10px;display:none"></div>
  <form id="regForm1" class="regForm" next="regForm2" >
    <ul>
      <li>
        <div class="para">
          <span>手机号</span>
          <div class="ipt"><input type="tel" placeholder="请输入您的手机号码" id="phone" name="telephone" require="true" regexp="^(0|86|17951)?(13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[57])[0-9]{8}$" value="" msg="请输入合法的手机号" /></div>
        </div>
        <div class="reg_notice"></div>
      </li>
      <li class="vcode">
        <div class="para">
          <span>验证码</span>
          <div class="ipt"><input type="text" id="vcode" placeholder="请输入验证码" require="true" regexp="^\d+$" msg="请输入验证码" name="verfiy" ></div>
        </div>
        <div class="get_code" id="get_code" onclick="actGetCode(this);">获取验证码</div>
        <div class="reg_notice"></div>
      </li>
      <li>
        <div class="para">
          <span>推荐码</span>
          <div class="ipt"><input type="text" placeholder="请输入推荐码，没有可不填写" name="admin_work_code" ></div>
        </div>
        <div class="reg_notice"></div>
      </li>
    </ul>
    <input type="submit" class="submit action-submit" value="立即免费领取">
    
  </form>

  <form id="regForm2" class="regForm" next="regfinish" style="display:none">
    <ul>
      <li>
        <div class="para">
          <span>孩子姓名</span>
          <div class="ipt"><input name="fullname" type="text" id="name"  placeholder="请输入孩子姓名" require="true" regexp="^[\u0391-\uFFE5]+$" msg="请输入中文姓名" >
          </div>
        </div>
        <div class="reg_notice"></div>
      </li>
      <li>
        <div class="para">
          <span>孩子年龄</span>
          <div class="ipt">
            <select name="generation">

              <foreach  name="generation" item="vo"  >
                  <option value="{$key}">{$vo}</option>
              </foreach>
            </select>
          </div>
        </div>
        <div class="reg_notice"></div>
      </li>
      <li>
        <div class="para">
          <span>所在年级</span>
          <div class="ipt">
            <select name="grade">
               
              <foreach  name="grade" item="vo"  >
                  <option value="{$key}">{$vo}</option>
              </foreach>

 
            </select>
          </div>
        </div>
        <div class="reg_notice"></div>
      </li>
    </ul>
    <input type="submit" class="submit action-submit" value="完善资料，立即免费领取">
    
  </form>

  <div class="right regfinish" id="regfinish" style="display:none">
    免费课程申请成功！
  </div>

</section>

<div id="sms" style="display:none"></div>

<script>
var _pageVar = {};
  _pageVar.telephone = {};
  $(document).on("click",".action-submit",function(){
      

     _self = this;
      _e2 = _self.parentElement;
     _e3 = $(_e2).find("input");
     //$(_e3).parents("li").find(".reg_notice").html("xxx")
      for(i=0;i<_e3.length;i++) {
        checkData(_e3[i]);
      }

      if ($(this).parents("form").attr("id")=="regForm1") {
        if (!_pageVar.telephone.status) {
            $("#phone").parents("li").find(".reg_notice").html("未获取验证码或获取失败");
            return false;
        }
        checkVerfiy(nextFormView,_self);
        return false;
      } else {
        if (_pageVar.pass) {
          nextFormView(_self);
        }

      }
      return false;

  })

  function nextFormView(_self) {
     _nextFrom = $(_self).parents("form").attr("next");
  
          if (_nextFrom) {
              if (_nextFrom=='regfinish') {
                  jSubmit();
              } else {
                $(_self).parents("form").hide();
                $("#"+_nextFrom).show();
                return false;
              }
          }
  }
  $(document).on("click","input",function(){

       _self = this;
      _eReg_notice = $(_self).parents("li").find(".reg_notice");
      _eReg_notice.html('');
      
  })

 

  function checkTelephone(callfun) {
       
        //手机号

        _pageVar.telephone = {};
        _telephone = $("#phone").val() ;
        if (!_telephone) {
          _pageVar.telephone.status = false;
          _pageVar.telephone.msg = "手机号未输入";
          $("#phone").parents("li").find(".reg_notice").html(_pageVar.telephone.msg);
          return false;
        }  
     
        _regExp = /^(0|86|17951)?(13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[57])[0-9]{8}$/gi;
        if (!_regExp.test(_telephone)) {
          _pageVar.telephone.status = false;
          _pageVar.telephone.msg = "手机号输入非法";
          $("#phone").parents("li").find(".reg_notice").html(_pageVar.telephone.msg);
          return false;
        }


          $.ajax({
             type: "POST",
             url: "{:U('user/verifyTelephone')}",
             data: "telephone="+_telephone+"&ajax=1",
             success: function(res){
                _obj = eval("("+res+")");
                if (_obj.status == "error") {
                    //$(".notice_msg").html(_obj.msg);
                   // $(".notice_msg").show();
                    _pageVar.pass = false;
                    _pageVar.telephone.status = false;
                    _pageVar.telephone.msg = _obj.msg;
                    $("#phone").parents("li").find(".reg_notice").html(_obj.msg);
                    return false;
                } else {
                   // $(".notice_msg").hide();
                    _pageVar.pass = 1;
                    _pageVar.telephone.status = 1;
                   if (callfun) callfun();
                    return true;
                }
                   
             }
          });
  }

  function checkData(_self) {
  
 
        _e3 = _self;
        _e4 = $(_e3);  
        _pageVar.pass = 1;
        if (_e4.attr("require")=="true"   ) {
            _str = _e4.attr("regexp");
            _val = _e4.val();
            _regExp = new RegExp(_str);
           _eReg_notice = $(_e4).parents("li").find(".reg_notice");
           if (!_regExp.test(_val)) {
              _msg = $(_e3).attr("msg");
              
              _eReg_notice.html(_msg);
              _eReg_notice.show();
              _pageVar.pass = false;
              return false;
   
           } else {
              _eReg_notice.html('');
           }

        }

       

    
  } 

//验证码
function checkVerfiy(callfun,arge1){

    //手机号
    if (!_pageVar.telephone.status) {
          $("#phone").parents("li").find(".reg_notice").html(_pageVar.telephone.msg);
          return false;
    }
 
 
    _code = $("#vcode").val() ;
    if (!_code) {
        _pageVar.pass = false;
         $("#vcode").parents("li").find(".reg_notice").html("未输入验证码");
          return false;
        
    } 

    $.ajax({
       type: "POST",
       url: "{:U('user/verify')}",
       data: "telephone="+_telephone+"&code="+_code,
       success: function(res){

          _obj = eval("("+res+")");
          if (_obj.status == "error") {
               $("#vcode").parents("li").find(".reg_notice").html("验证码输入错误");
              _pageVar.pass = false;
              _pageVar.vcode = false;
              return false;
          } else {
              $(".notice_msg").hide();
              _pageVar.pass = 1;
               
              if (callfun) callfun(arge1);
              return true;
          }
          return false;     
       }
    });


       
        
     
}

/*
$(document).on("click","#get_code",function(){
    //手机号
    checkTelephone(get_code2);
})
*/

function actGetCode() {
    if (_pageVar.sendsms_disable) return false;
  //手机号
    checkTelephone(get_code2);
}

function get_code2() {
  
    _self = $("#get_code");
    _self.addClass("disable");
 
    _data = "telephone="+$("#phone").val();
 
    if (_pageVar.sendsms_disable) return false;
    $.ajax({
       type: "POST",
       url: "{:U('user/crateaVerify')}",
       data: _data,
       success: function(res){
          
          
          _pageVar.sendsms_disable = 1;
          _obj = eval("("+res+")");
          if (_obj.status == "error") {
              if (_obj.id) {
                $("#"+_obj.id).parents("li").find(".reg_notice").html(_obj.msg);
              } else {
                  $(".notice_msg").html(_obj.msg);
                  $(".notice_msg").show();
              }
              _self.removeClass("disable");
              
              _pageVar.pass = false;
              _pageVar.sendsms_disable = false;
              return false;
          } else {
              loopTime(_self);
              $(".notice_msg").hide();
              _pageVar.pass = 1;              
              //发手机短信,注册码                             
              $.post("{:U('user/regsendsms')}",_data);
              return true;
          }
             
       }
    });

}


function loopTime(obj) {
    _pageVar.sendsms_disable = 1;
    var n = 60;
          obj.addClass("disable").text("等待"+n+"秒"); 
          obj.text("等待"+n+"秒");
            var count = setInterval(function(){
              n --;
              obj.text("等待"+n+"秒");
              if(n == 0){
                clearInterval(count);
                _pageVar.sendsms_disable = false;
                obj.text("重新获取").removeClass("disable");
              }
            },1000);

}
 
function jSubmit() {

  _data = $("form").serialize();
 
  $.post("{:U('user/register')}",_data,function(rs){
      _obj = eval("("+rs+")");
      if (_obj.status=="success") {
     
          $("#regForm2").hide();
          _nextFrom = $("#regForm2").attr("next");
          $("#"+_nextFrom).show();
        
          if (_nextFrom=='regfinish') {
            //成功后，发送短信
              regsuccess_sendsms();
          }
          return false;
      } else {
          $(".notice_msg").html(_obj.msg);
          $(".notice_msg").show();
          return false;
      }
  })
}

function regsuccess_sendsms() {
    _data = "telephone="+$("#phone").val();
    $.post("{:U('user/regsuccess_sendsms')}",_data);
    return false;
}
</script>
</body>
</html>
